/**
 * Created by huangxiaolu on 2014/4/8.
 */
var express = require('express');
var app = express();
var http = require('http');

function respond(req,res,next){
    console.log('ready to redirect');

    var options = {
        hostname: 'localhost',
        port: 3001,
        path: '/hola/'+req.params.name,
        method:req.method,
        headers: req.headers
    };
    var requestClient =  http.request(options,function(res1) {
        console.log('STATUS: ' + res1.statusCode);
        console.log('HEADERS: ' + JSON.stringify(res1.headers));
        res1.setEncoding('utf8');
        res1.on('data', function (chunk) {
            console.log('BODY: ' + chunk);
        });
    });
    requestClient.end();


    //req.url ='http://localhost:3001/hola/'+req.params.name;
    //next('route');
    //res.send('hola '+req.params.name);
}
app.get('/hola/:name',respond);

app.listen(3000);
console.log('express_rest listening on port 3000');